

package com.maoshi.shop.distribution.platform.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.maoshi.shop.common.util.PageParam;
import com.maoshi.shop.distribution.comment.model.DistributionWithdrawCash;
import com.maoshi.shop.distribution.comment.param.RangeTimeParam;
import com.maoshi.shop.distribution.comment.service.DistributionUserService;
import com.maoshi.shop.distribution.comment.service.DistributionUserWalletService;
import com.maoshi.shop.distribution.comment.service.DistributionWithdrawCashService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lgh on 2019/04/01.
 */
@RestController
@RequestMapping("/platform/distributionWithdrawCash")
public class DistributionWithdrawCashController {

    @Autowired
    private DistributionWithdrawCashService distributionWithdrawCashService;
    @Autowired
    private DistributionUserWalletService distributionUserWalletService;
    @Autowired
    private DistributionUserService distributionUserService;

    /**
     * 分页获取
     */
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('platform:distributionWithdrawCash:page')")
    public ResponseEntity<IPage<DistributionWithdrawCash>> page(PageParam<DistributionWithdrawCash> page, RangeTimeParam rangeTimeParam,
                                                                String userMobile, DistributionWithdrawCash distributionWithdrawCash) {
        IPage<DistributionWithdrawCash> list = distributionWithdrawCashService.distributionWithdrawCashsPage(page, null, rangeTimeParam, userMobile, distributionWithdrawCash);
        return ResponseEntity.ok(list);
    }

//    /**
//     * 修改
//     */
//    @PutMapping("/toSuccess/{withdrawCashId}")
//    @PreAuthorize("@pms.hasPermission('distribution:distributionWithdrawCash:update')")
//    public ResponseEntity<Void> update(@PathVariable String withdrawCashId) {
//        DistributionWithdrawCash distributionWithdrawCash = distributionWithdrawCashService.getById(withdrawCashId);
//        if (distributionWithdrawCash == null) {
//            throw new MaoshiShopBindException("无法获取提现信息");
//        }
//        Long walletId = distributionWithdrawCash.getWalletId();
//
//        DistributionUserWallet wallet = distributionUserWalletService.getById(walletId);
//
//        if (wallet == null) {
//            throw new MaoshiShopBindException("无法获取用户钱包信息");
//        }
//
//        DistributionUser distributionUser = distributionUserService.getById(wallet.getDistributionUserId());
//
//        if (distributionUser == null) {
//            throw new MaoshiShopBindException("无法获取用户信息");
//        }
//
//        if (!Objects.equals(distributionUser.getShopId(), Constant.PLATFORM_SHOP_ID)) {
//            throw new MaoshiShopBindException("没有权限修改提现信息");
//        }
//
//        distributionWithdrawCash.setState(1);
//        distributionWithdrawCash.setUpdateTime(new Date());
//        distributionWithdrawCashService.updateById(distributionWithdrawCash);
//        return ResponseEntity.ok().build();
//    }

}
